//
//  HWHomePageViewController.m
//  HuaiWu
//
//  Created by HuaiWu on 2022.
//  Copyright © 2022 HuaiWu. All rights reserved.
//

#import "HWHomePageViewController.h"

#import "HWSetUpViewController.h" //设置
#import "HWMuYuViewController.h" //木鱼
#import "HWTeaClockViewController.h" //奶茶打卡记录
#import "HWStoneScissorClothViewController.h" //石头剪刀布
#import "HWSubscribeViewController.h"

#import "HWHomeFunctionCell.h"

@interface HWHomePageViewController ()

@end

@implementation HWHomePageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = UIColorFromHex(0xE9EDF9);
    self.leftItem.hidden = YES;
    [self setRightItemWithIcon:[UIImage imageNamed:@"home_set"] selector:@selector(gotoSetUpViewController)];
    [self.view bringSubviewToFront:self.navigationBar];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"HWHomeFunctionCell" bundle:nil] forCellReuseIdentifier:@"HWHomeFunctionCell"];
    
    self.tableView.frame = CGRectMake(0,-self.statusBarHeight, kScreenWidth,kScreenHeight + self.statusBarHeight);
    
    if (!kUserManager.userManager.isSubscribe) {

        if (![[[NSUserDefaults standardUserDefaults] objectForKey:@"isFirstEnter"] boolValue]) {
            HWSubscribeViewController *vc = [HWSubscribeViewController new];
            vc.modalPresentationStyle = UIModalPresentationFullScreen;
            [self.navigationController presentViewController:vc animated:YES completion:nil];
        }
    }
}

#pragma mark - cellDataSource

- (NSArray *)cellDataSource {
    
    if (!self.dataSource) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:4];
        
        __block NSMutableArray *subarr = nil;
        __block NSDictionary *dict = nil;

        subarr = [NSMutableArray arrayWithCapacity:1];
                
        dict =  @{@"class":HWHomeFunctionCell.class,
                  @"height":@([HWHomeFunctionCell getCellFrame:[NSNumber numberWithFloat:kScreenWidth*812/375]]),
                  @"delegate":@YES};
        [subarr addObject:dict];

        [arr addObject:subarr];
        
        self.dataSource = arr;
    }
    return self.dataSource;
}

#pragma mark HWHomeFunctionCellDelegate 木鱼 奶茶打卡记录 石头剪刀布

- (void)homeFunctionCell:(HWHomeFunctionCell *)cell button:(UIButton *)sender {
    if (!kUserManager.userManager.isSubscribe) {
        [self gotoSubscribeViewController];
        return;
    }
    
    if (sender.tag == 10) {
        //木鱼
        [self gotoMuYuViewController];
    } else if (sender.tag == 11) {
        //奶茶打卡记录
        [self gotoTeaClockViewController];
    } else if (sender.tag == 12) {
        //石头剪刀布
        [self gotoStoneScissorClothViewController];
    }
}

#pragma mark - goto

//设置
- (void)gotoSetUpViewController {
    HWSetUpViewController* vc = [HWSetUpViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//木鱼
- (void)gotoMuYuViewController {
    HWMuYuViewController *vc = [[HWMuYuViewController alloc] init];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//奶茶打卡记录
- (void)gotoTeaClockViewController {
    HWTeaClockViewController* vc = [HWTeaClockViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

//石头剪刀布
- (void)gotoStoneScissorClothViewController {
    HWStoneScissorClothViewController* vc = [HWStoneScissorClothViewController new];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end
